package com.rfid.project.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.rfid.project.model.People;
import com.rfid.project.model.Position;
import com.rfid.project.model.ProjectFinishApply;
import com.rfid.project.model.ProjectStakeholderType;

@Service
@Transactional
public class ProcessSourceForProjectFinishApply {

	@Autowired
	private ProjectFinishApplyService projectFinishApplyService;

	@Autowired
	private PeopleService peopleService;

	public List<Process> getCurrentTaskListByProcessor(People people) {
		List<Process> resultList = new ArrayList<Process>();
		List<ProjectFinishApply> projectFinishApplies = null;
		if (people.getPosition().getId().equals(Position.COMPANY_MANAGER_ID)) {
			// 如果当前用户为事业部领导，则查询所有状态为审核的项目完结申请
			projectFinishApplies = projectFinishApplyService.findByStatus(people, ProjectStakeholderType.DEPT_MANAGER, ProcessStatus.EXAMINE_SUCCESS);
		} else if (people.getPosition().getId().equals(Position.PLAN_ID)) {
			// 如果当前用户为计划调度岗，则查询所有状态为提交的项目完结申请
			projectFinishApplies = projectFinishApplyService.findByStatus(people, ProjectStakeholderType.DEPT_PLAN, ProcessStatus.FINISH_APPLY);
		}

		if (projectFinishApplies != null) {
			for (ProjectFinishApply projectFinishApply : projectFinishApplies) {
				Process processTask = new Process();
				processTask.setBizId(projectFinishApply.getId());
				processTask.setSubmitPerson(projectFinishApply.getApplyPerson());
				processTask.setSubmitTime(projectFinishApply.getApplyTime());
				processTask.setProcessStatusId(projectFinishApply.getStatus());
				processTask.setProcessTypeId(ProcessType.PROJECT_FINISH);
				processTask.setProcessTitle(projectFinishApply.getProject()
						.getName() + "_申请完结!");
				resultList.add(processTask);
			}
		}
		return resultList;
	}

	public List<Process> getCurrentTaskListByCreator(Long userId) {
		// TODO Auto-generated method stub
		return null;
	}

	public List<Process> getHistoryTaskListByProcessor(Long userId) {
		// TODO Auto-generated method stub
		return null;
	}

	public List<Process> getHistoryTaskListByCreator(Long userId) {
		// TODO Auto-generated method stub
		return null;
	}

}
